<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录页面</title>
    <link rel="stylesheet" href="index.css">
    <link rel="stylesheet" href="register.css">
    <link rel="stylesheet" href="login.css">
</head>

<body>
    <header>
        <div class="nav">
            <!-- 头部左侧文字链接 -->
            <ul class="nav-left">
                <li class="conweixin">
                    <a href="javascript:;">关注</a>
                    <div class="weixin">
                        <div class="weixin-con">
                            <img src="img/weChat.jpg" alt="">
                            <p>关注公众号</p>
                        </div>
                    </div>
                </li>
                <li class="loadapp">
                    <a href="javascript:;">下载APP</a>
                    <div class="app">
                        <div class="app-con">
                            <img src="img/app.jpg" alt="">
                            <p>优购app下载</p>
                        </div>
                    </div>
                </li>
            </ul>

            <!-- 头部右侧文字链接 -->
            <ul class="nav-right">
                <li>
                    <a href="login.html">登录</a>
                    <span>/</span>
                    <a href="register.html">注册</a>
                </li>
                <li class="collect">
                    <a href="#"><i></i>收藏</a>
                </li>
                <li class="bag">
                    <a href="car.html"><i></i>购物袋</a>
                </li>
                <li class="publicword">
                    <a href="javascript:;">公告</a>
                    <div class="public">
                        <ul class="public-con">
                            <li><a href="javascript" class="red">近期物流情况安排通知</a></li>
                            <li><a href="javascript">优购客服电话变更</a></li>
                            <li><a href="javascript">关闭分享购频道</a></li>
                            <li><a href="javascript">提醒会员谨防诈骗电话</a></li>
                        </ul>
                    </div>
                </li>
            </ul>
        </div>
    </header>

    <section>
        <div class="sec-con">
            <img src="img/register-logo.png" alt="">
            <span>新用户注册</span>
        </div>

        <div class="bannerpic">
            <div class="banner-con">
                <img src="img/pic.jpg" alt="">
                <div class="register">
                    <div class="reg-con">
                        <ul class="word">
                            <li><a href="login.html">登录</a></li>
                        </ul>
                        <div class="reg-in">
                            <!-- 手机号 -->
                            <div class="phonenum">
                                <p>
                                    <label for="phone"></label>
                                    <input type="text" id="phone" placeholder="手机号/邮箱">
                                </p>
                                <div class="yzphone">
                                    <span class="right"></span>
                                    <span class="wrong">请正确输入手机号码</span>
                                </div>
                            </div>

                            <!-- 密码 -->
                            <div class="pwdnum">
                                <p>
                                    <label for="password"></label>
                                    <input type="password" id="password" placeholder="请输入密码">
                                </p>
                                <div class="yzpwd">
                                    <span class="right"></span>
                                    <span class="wrong">请正确输入密码</span>
                                </div>
                            </div>

                            <!-- 自动登录 -->
                            <!-- <div class="remember">
                                <input type="checkbox" id="auto">
                                <label for="auto">下次自动登录</label>
                            </div> -->
                            <a href="javascript:;" style="color: #666;text-decoration: underline;display: block;text-align: right;margin-right: 25px;">忘记密码</a>


                            <!-- 去注册按钮 -->
                            <button id="gologin">点击登录</button>

                            <div style="text-align: center;">
                                使用合作网站账号登录优购：
                            </div>

                            <div class="share">
                                <a href="javascript:;" class="wx"></a>|
                                <a href="javascript:;" class="zfb"></a>|
                                <a href="javascript:;" class="QQ"></a>|
                                <a href="javascript:;" class="wb"></a>|
                                <a href="javascript:;" class="other"></a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <footer>Copyright © 2011-2014 Yougou Technology Co., Ltd.&nbsp;&nbsp;&nbsp;&nbsp;<span>粤ICP备09070608号-4</span>&nbsp;&nbsp;&nbsp;&nbsp;增值电信业务经营许可证：<span>粤 B2-20090203</span></footer>
</body>

</html>

<script src="jquery.min.js"></script>
<script src="index.js"></script>
<script>
    // $(function() {
    //     let username = localStorage.getItem("username");
    //     let password = localStorage.getItem("password");

    //     if (username && password) {
    //         $("#username").val(username);
    //         $("#password").val(password);
    //         // $("#gologin").click()
    //     }
    // })

    $(function() {
        let uname = sessionStorage.getItem("uname");
        // console.log(uname);
        if (uname) {
            $(".bag a").attr("href", `/car?username=${uname}`);
        } else {
            $(".bag a").click(function() {

                alert("请先登录/注册您的账号")
            })
        }

    })

    $("#gologin").click(function() {
        if ($("#phone").val() && $("#password").val()) {
            let uname = $("#phone").val();
            let pwd = $("#password").val();

            $.ajax({
                url: "http://10.35.164.244:8080/goLogin",
                data: {
                    username: uname,
                    password: pwd
                },
                success(data) {
                    if (data === "none") {
                        alert("该用户名未注册，请前往注册页面进行注册")
                        return;
                    }
                    if (data === "success") {
                        alert("登录成功");

                        //存储
                        sessionStorage.setItem("uname", uname);
                        sessionStorage.setItem("pwd", pwd);

                        location.href = "http://10.35.164.244:8080/index.html";
                    } else {
                        alert("用户名或密码输入错误");
                        history.go(0)
                    }
                }
            })

        }
    })
</script>